package com.sync.syncmasterdata.configuration;

import lombok.Data;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.config.AuthSchemes;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Data
@Component
@ConfigurationProperties(prefix = "myprops")
public class ConfInfo {

    @Value("${myprops.u8url}")
    private String u8url;

    @Value("${myprops.crmurl}")
    private String crmurl;

    @Value("${myprops.oaurl}")
    private String oaurl;

    @Value("${myprops.u8opeapiurl}")
    private String u8opeapiurl;

    @Value("${myprops.dss}")
    private String ds_s;

    //钉钉机器人参数
    @Value("${myprops.rebotKey}")
    private String rebotKey;
    @Value("${myprops.rebotSecret}")
    private String rebotSecret;


    public CloseableHttpClient getAuthHttp(){
        RequestConfig requestConfig = RequestConfig.custom().setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM)).setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC)).build();
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials("test", "Bio-San@123", this.crmurl, "biosan"));
        return HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).setDefaultRequestConfig(requestConfig).build();
    }
}
